import {
    Column,
    CreateDateColumn,
    Entity,
    Index,
    JoinColumn,
    OneToOne,
    PrimaryGeneratedColumn,
    UpdateDateColumn,
} from 'typeorm';
import { FileStorage } from './FileStorage';
import { Transform } from 'class-transformer';

@Entity()
export class FileInfo {

    @PrimaryGeneratedColumn('uuid')
    id: string;

    @Index()
    @Column({nullable: false})
    name!: string;

    @Index()
    @Column({nullable: false})
    extname!: string;

    @OneToOne(() => FileStorage, {cascade: true})
    @JoinColumn()
    fileStorage!: FileStorage;

    @Column({default: 0})
    viewCount!: number;

    @Column({default: 0})
    score!: number;

    @Column({default: false})
    star!: boolean;

    @UpdateDateColumn()
    @Transform(params => params.value.valueOf())
    updateDate!: Date;

    @CreateDateColumn()
    @Transform(params => params.value.valueOf())
    createDate!: Date;
}

